/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-16 14:54:59
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-16 14:55:09
 * @FilePath: /algorithm/每日一题13.搜索二维矩阵II(medium).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/search-a-2d-matrix-ii
 */
class Solution {
public:
    bool search(vector<int> &arr, int &target) {
        int left = 0, right = arr.size() - 1;
        while(left < right) {
            int mid = left + ((right - left) >> 2);
            if(arr[mid] < target) left = mid + 1;
            else right = mid;
        }
        if(arr[left] == target) return true;
        else return false;
    }
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        // 每行都进行二分查找
        for(auto &row : matrix) {
            bool ret = search(row, target);
            if(ret) return true;
        }
        return false;
    }
};